package com.lmoumou.calendar

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.lmoumou.lib_calendarview.entity.DayAttrsBeen
import com.lmoumou.lib_calendarview.entity.DayBeen
import com.lmoumou.lib_calendarview.utils.CalendarUtils
import com.lmoumou.lib_calendarview.widget.CalendarView
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*

class MainActivity : AppCompatActivity() {

    companion object {
        private const val TAG = "MainActivity"
    }

    private val testMap = linkedMapOf<String, DayAttrsBeen>()
    private var selectKey = "2019-11-06"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initCalendarView()
        Calendar.getInstance().apply {

            CalendarUtils.getDaysOfMoth(get(Calendar.YEAR), get(Calendar.MONTH) + 1).forEach {
                Log.e(TAG, "$it")
            }
        }

        mCalendarView.listener = object : CalendarView.OnItemClickListener {
            override fun onItemClick(data: DayBeen, position1: Int, position2: Int) {
                testMap[selectKey]?.apply {
                    isSelect = false
                }
                selectKey = data.date
                val dayAttrsBeen = data.dayAttrs
                if (dayAttrsBeen == null) {
                    testMap[selectKey] = DayAttrsBeen(true)
                } else {
                    testMap[selectKey] = dayAttrsBeen.apply {
                        isSelect = true
                    }
                }

                mCalendarView.setSpecialMap(testMap)
            }
        }
        testMap[selectKey] = DayAttrsBeen(true, false, 1)
        testMap["2019-11-07"] = DayAttrsBeen(false, false, 2, 1)
        testMap["2019-11-08"] = DayAttrsBeen(false, false, 2,2)
        testMap["2019-11-09"] = DayAttrsBeen(false, false, 2,2)
        testMap["2019-11-10"] = DayAttrsBeen(false, false, 2,2)
        testMap["2019-11-11"] = DayAttrsBeen(false, false, 2, 3)
        testMap["2019-11-13"] = DayAttrsBeen(false, true, 3)
        testMap["2019-11-14"] = DayAttrsBeen(false, true, 3)
        testMap["2019-11-15"] = DayAttrsBeen(false, true, 3)

        testMap["2019-11-17"] = DayAttrsBeen(false, true, 4)
        testMap["2019-11-18"] = DayAttrsBeen(false, true, 4)
        testMap["2019-11-19"] = DayAttrsBeen(false, true, 4)
        testMap["2019-11-20"] = DayAttrsBeen(false, true, 4)
        mCalendarView.setSpecialMap(testMap)

    }

    private fun initCalendarView() {

    }
}
